package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    @PostMapping("/create")
    @ApiOperation(value = "添加床位", notes = "传入床位Bed")
    public ResponseResult insertBed(@ApiParam(value = "床位对象", required = true) @RequestBody BedDto bedDto) {
        bedService.insertBed(bedDto);

        return success();
    }
    @ApiOperation(value = "根据床位id查询床位", notes = "传入床位id")
    @GetMapping("/read/{Id}")
    public ResponseResult<BedVo> readBedById(
            @ApiParam(value = "床位ID", required = true) @PathVariable("Id") Long Id){
        BedVo bedVos=bedService.getBedsById(Id);

        return success(bedVos);
    }
    @ApiOperation(value = "更新床位信息", notes = "传入床位id")
    @PutMapping("/update")
    public ResponseResult updateBed(@ApiParam(value = "床位对象", required = true) @RequestBody BedDto bedDto){

       int i= bedService.updateBed(bedDto);

        return toAjax(i);
    }
    @DeleteMapping("/delete/{id}")

    @ApiOperation(value = "删除床位对象", notes = "传入床位id")

    public ResponseResult deleteBed(@ApiParam(value = "床位对象", required = true) @PathVariable Integer id){

        int i =bedService.deleteBed(id);
        return toAjax(i);
    }
}

